﻿/*======================================*\
* Author: Vincent
* LastModifyUser: Vincent
* Description:  
* CreateTime： 2012-05
* Remark:  
\*======================================*/
using System;
using System.Drawing;
using System.Windows.Forms;
using AppCode.Domain.Services;

namespace Vincent.AutoCode  
{
    /// <summary>
    /// 主窗体类分部
    /// <remarks>
    /// 日志记录部分
    /// </remarks>
    /// </summary>
    public partial class frmMain
    {
        #region 日志记录

        Action<string> _acStatus;
        /// <summary>
        /// 状态信息通知
        /// </summary>
        /// <param name="msg"></param>
        void WriteStatusInfo(string msg)
        {
            if (statusStrip1.InvokeRequired)
            {
                _acStatus = WriteStatusInfo;
                statusStrip1.BeginInvoke(_acStatus, new object[] { msg });
            }
            else
                statusMainInfo.Text = msg;
        }

        Action<string> _acLog;
        /// <summary>
        /// 日志记录到文本框
        /// </summary>
        /// <param name="msg"></param>
        void WriteLogToRichTextBox(string msg)
        {
            if (rtbLog.InvokeRequired)
            {
                _acLog = WriteLogToRichTextBox;
                rtbLog.BeginInvoke(_acLog, new object[] { msg });
            }
            else
            {
                rtbLog.AppendText(msg);
                rtbLog.Focus();
                rtbLog.Select(rtbLog.Text.Length, 0);
                rtbLog.ScrollToCaret();
            }
        }

        /// <summary>
        /// 日志记录到文本框(自定义颜色）
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="f"></param>
        void WriteLogToRichTextBox(string msg,Color c)
        {
            if (rtbLog.InvokeRequired)
            {
                _acLog = WriteLogToRichTextBox;
                rtbLog.BeginInvoke(_acLog, new object[] { msg });
            }
            else
            {
                rtbLog.AppendText(msg);
                rtbLog.Focus();
                rtbLog.SelectionColor = c;
                rtbLog.Select(rtbLog.Text.Length, 0);
                rtbLog.ScrollToCaret();
            }
        }

        #endregion
    }
}
